package cn.itcast.order.web;

import cn.itcast.feign.client.UserClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private OrderService orderService;

//   @Autowired
//   private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;


    @GetMapping("{orderId}")
    public Order queryOrderByUserId( @PathVariable("orderId") Long orderId,@RequestHeader(value = "name", required = false) String name) {
        // 根据id查询订单并返回
        log.warn("请求头name的值：{}",name );
        Order order = orderService.queryOrderById(orderId);
//        String url = "http://userservice/user/" + order.getUserId();
//        User user = restTemplate.getForObject(url, User.class);
        User user = userClient.findById(order.getUserId());
        order.setUser(user);


        return order;
    }
}
